#include"SelectSort.h"

void Swap(int* x1, int* x2)
{
	int mid = *x1;
	*x1 = *x2;
	*x2 = mid;
}

void SelectSort(int* arr, size_t r)
{
	int left = -1; int right = r;
	while (left < right)
	{
		left++; right--;
		int mi = left, ma = left;
		int begin = left, end = right;
		for (int i = begin; i <= end; i++)
		{
			if (arr[i] < arr[mi]) mi=i;
			if (arr[i] > arr[ma]) ma=i;
		}
		Swap(arr+left, arr+mi);
		if (ma==left)
		{
			ma=left;
		}
		Swap(arr+right, arr+ma);
	}
}
